<?php

use Swoole\Coroutine\Client;
use function Swoole\Coroutine\run;

$message = 'Hi';
/*$params = getopt('a:');
$message = isset($params['a']) ? $params['a'] : '你好';*/


run(function () {
    $Client = new Client(SWOOLE_SOCK_TCP);
    if (!$Client->connect('127.0.0.1', 9503, 0.5)){
        echo "connect failed. Error: {$Client->errCode}\n";
    }

	while (true) {
		$data = $Client->recv();
        if (strlen($data) > 0) {
            echo $data;
        }
        
		fwrite(STDOUT,'please input:');
		$message = fgets(STDIN);
	    if (strlen($message)) {
			$Client->send($message); //hello world\n
		}
    }
});
